<?php
class FMIS_Controller extends CI_Controller {

    private $debug_names = array(
        '0' => 'Visitor',
        '1' => 'Temoto-kun',
        '2' => 'Temoko-chan'
    );

	private $mime_desc = array(
		'documents' => array(
			'application/powerpoint' => "PowerPoint Presentation",
			'application/vnd.ms-powerpoint' => "PowerPoint Presentation",
            'application/vnd.openxmlformats-officedocument.presentationml.presentation' => "PowerPoint Presentation",
			'application/excel' => "Excel Spreadsheet",
			'application/vnd.ms-excel' => "Excel Spreadsheet",
			'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => "Excel Spreadsheet",
			'application/msexcel' => "Excel Spreadsheet",
			'application/pdf' => "Portable Document Format",
			'application/msword' => "Word Document",
			'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => "Word Document",
			'text/html' => "HyperText Markup Language File",
			'text/latex' => "TeX File",
			'text/rtf' => "Rich Text File",
			'text/plain' => "Text File"
		),
		'images' => array(
			'jpeg' => "JPEG Image"
			// TODO add more in these...
		)
	);

    public function __construct() {
        parent::__construct();

        //$user_id_cookie = $this->input->cookie('fmis_user_id');
        //$user_id = isset($user_id_cookie) ? $user_id_cookie : 0;
        //$this->load->helper('url');
        //$this->data = array(
        //    'base_url' => base_url(),
        //   'app_title' => "Faculty Management Information System",
        //    'user_id' => $user_id,
        //    'user_name' => $this->debug_names[$user_id],
	    //    'uploads_dir' => './uploads'
        //);

        //session_destroy();
        $newdata = array(
           'base_url'  => base_url()
        );
        $this->session->set_userdata($newdata);
    }

    protected function setup_view($view_name, $data = array())
    {
        $CI =& get_instance();
        $data = array_merge($CI->session->all_userdata(), $data);


        $CI->load->view('templates/header', $data);
        $CI->load->view('templates/hidden', $data);
        $CI->load->view('templates/nav', $data);
        if(!isset($data['username']))
        {
            redirect('home');
        }
        else
            $CI->load->view($view_name, $data);
        $CI->load->view('templates/footer', $data);
    }

/*
    protected function set_login_page()
    {
        $logged_in = $this->session->userdata('logged_in');
        if( $logged_in == false || $logged_in == '')
        {
            $data = array(
               'page_title'  => 'Log-in'
            );
            $this->setup_view('fmis/login', $data);
        } 
        else
        {
            redirect('profile');
        }
    }
    */

    //THIS SHOULDN'T BE HERE
    /*public function documents() {
        // TODO store metadata of uploaded files in database.
        $this->load->database();

        $this->setup_view('documents',
			array(
			     'page_title' => "Documents",
			     'message' => '',
			     'uploads' => get_filenames("{$this->data['uploads_dir']}/doc", TRUE),
			     'mime_desc' => $this->mime_desc['documents']
			)
        );
    }

    public function information(){
        $this->setup_view('information', array('page_title' => "Information"));
    }

    public function members() {
        $this->setup_view('members', array('page_title' => "Members"));
    }

    public function meeting() {
        $this->setup_view('meeting', array('page_title' => "Meetings"));
    }

    public function ethics() {
        $this->setup_view('ethics', array('page_title' => "Code of Ethics"));
    }
    //*/
}